#ifndef DELAY_H_
#define DELAY_H_

#include "../Communication/SPI.h"

/*
 * Utility file for creating delays of appropriate length.  This is mainly
 * used in the manual bit banging SPI for the SPI interface sensors to generate
 * appropriate waveforms and communication delays.  The macros are self explanatory
 * and are fairly accurate (minus interrupt overhead, etc.).  These are based
 * on a 16MHz clock assumption and may be off... Future developers are
 * encouraged to verify these timings but they worked for doing SPI communication
 * with the sensors.
 */

#define DELAY_250NS() \
	{\
		_NOP();\
		_NOP();\
		_NOP();\
		_NOP();\
	}
#define DELAY_1US() \
	{\
		DELAY_250NS();\
		DELAY_250NS();\
		DELAY_250NS();\
		DELAY_250NS();\
	}
#define DELAY_10US() \
	{\
		DELAY_1US();\
		DELAY_1US();\
		DELAY_1US();\
		DELAY_1US();\
		DELAY_1US();\
		DELAY_1US();\
		DELAY_1US();\
		DELAY_1US();\
		DELAY_1US();\
		DELAY_1US();\
	}
#define DELAY_50US() \
	{\
		DELAY_10US();\
		DELAY_10US();\
		DELAY_10US();\
		DELAY_10US();\
		DELAY_10US();\
	}

#define CLK_DELAY_250NS() \
	{\
		SCLK_HIGH();\
		_NOP();\
		SCLK_LOW();\
		_NOP();\
	}
#define CLK_DELAY_1US() \
	{\
		CLK_DELAY_250NS();\
		CLK_DELAY_250NS();\
		CLK_DELAY_250NS();\
		CLK_DELAY_250NS();\
	}
#define CLK_DELAY_10US() \
	{\
		CLK_DELAY_1US();\
		CLK_DELAY_1US();\
		CLK_DELAY_1US();\
		CLK_DELAY_1US();\
		CLK_DELAY_1US();\
		CLK_DELAY_1US();\
		CLK_DELAY_1US();\
		CLK_DELAY_1US();\
		CLK_DELAY_1US();\
		CLK_DELAY_1US();\
	}
#define CLK_DELAY_50US() \
	{\
		CLK_DELAY_10US();\
		CLK_DELAY_10US();\
		CLK_DELAY_10US();\
		CLK_DELAY_10US();\
		CLK_DELAY_10US();\
	}

#endif /*DELAY_H_*/
